
// 匹配h1-h6 的正则
let regexp_h1_h6 = {
    'h1': /^\s{0,3}(#)\s+(\S+)/,
    'h2': /^\s{0,3}(##)\s+(\S+)/,
    'h3': /^\s{0,3}(###)\s+(\S+)/,
    'h4': /^\s{0,3}(####)\s+(\S+)/,
    'h5': /^\s{0,3}(#####)\s+(\S+)/,
    'h6': /^\s{0,3}(######)\s+(\S+)/,
    handle (label, text) {
        return text.replace(this[label], function ( search, $1, $2, index, str ) {
            return `<span class="l-h-head">${$1}</span><span class="l-h-title"> ${$2}</span>`
        })
    }
}

export default {
    // text () {
    //
    // },
    h1 (text) {
        return regexp_h1_h6.handle('h1', text)
    },
    h2 (text) {
        return regexp_h1_h6.handle('h2', text)
    },
    h3 (text) {
        return regexp_h1_h6.handle('h3', text)
    },
    h4 (text) {
        return regexp_h1_h6.handle('h4', text)
    },
    h5 (text) {
        return regexp_h1_h6.handle('h5', text)
    },
    h6 (text) {
        return regexp_h1_h6.handle('h6', text)
    },
    highlight (text, regexp) {
        console.log(text)
        return text.replace(regexp, (search) => `<span class="l-highlight-code">${search}</span>` )
    },
}


